﻿<ContentControl x:Class="XCase.Gui.ProjectsWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Gui="clr-namespace:XCase.Gui"
    xmlns:Model="clr-namespace:XCase.Model;assembly=XCase.Model"
    Height="56" Width="1266" Name="projectsWindow"
	>
    <ContentControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/ResourceLibrary;component/Images/Images.xaml" ></ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </ContentControl.Resources>
    <DockPanel LastChildFill="True">
        <StackPanel Height="28" DockPanel.Dock="Top" Orientation="Horizontal" Visibility="Visible">
            <StackPanel.Background>
                <LinearGradientBrush ColorInterpolationMode="ScRgbLinearInterpolation" StartPoint="0,0" EndPoint="0,1">
                    <GradientStop Color="#D7E3F2" Offset="0.1"/>
                    <GradientStop Color="#E3F4FF" Offset="1"/>
                </LinearGradientBrush>
            </StackPanel.Background>
            <Label Height="28" Name="label1" Width="auto">Version:</Label>
            <ComboBox Name="cbBranches" Height="20" Width="120" ItemsSource="{Binding Versions}" DisplayMemberPath="Label" SelectionChanged="cbBranches_SelectionChanged" Background="#D7E3F2" ></ComboBox>
            <Button Height="21" Margin="10,0,0,0" Width="71" Name="bBranch" Click="Branch_Click" Background="#FFD7E3F2">Branch</Button>
            <Button Height="21" Margin="10,0,0,0" Width="111" Name="bRename" Click="Rename_Click" Background="#FFD7E3F2" IsEnabled="False">Rename version...</Button>
            <Button Height="21" Margin="10,0,0,0" Width="110" Name="bDelete" Click="Delete_Click" Background="#FFD7E3F2" IsEnabled="False">Remove version...</Button>
        </StackPanel>
        <TreeView Name="projectView" ItemTemplate="{DynamicResource projectTemplate}" SelectedItemChanged="OnItemSelected">
            <TreeView.Resources>
                <ContextMenu x:Key="projectContextMenu">
                    <MenuItem Header="Rename project" Click="OnProjectRenameClick">
                        <MenuItem.Icon>
                            <Image Source="{StaticResource pencil}" Width="20"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Header="Change project's namespace" Click="OnProjectChangeNamespaceClick">
                        <MenuItem.Icon>
                            <Image Source="{StaticResource pencil}" Width="20"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <Separator/>
                    <MenuItem Header="Add new PIM diagram..." Click="OnAddPIMDiagramClick">
                        <MenuItem.Icon>
                            <Image Source="{StaticResource GenericDocument}" Width="20"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Header="Add new PSM diagram..." Click="OnAddPSMDiagramClick">
                        <MenuItem.Icon>
                            <Image Source="{StaticResource GenericDocument}" Width="20"/>
                        </MenuItem.Icon>
                    </MenuItem>
                </ContextMenu>

                <ContextMenu x:Key="PIMDiagramContextMenu">
                    <MenuItem Header="Add new PIM diagram..." Click="OnAddPIMDiagramClick">
                        <MenuItem.Icon>
                            <Image Source="{StaticResource GenericDocument}" Width="20"/>
                        </MenuItem.Icon>
                    </MenuItem>
                </ContextMenu>

                <ContextMenu x:Key="PSMDiagramContextMenu">
                    <MenuItem Header="Add new PSM diagram..." Click="OnAddPSMDiagramClick">
                        <MenuItem.Icon>
                            <Image Source="{StaticResource GenericDocument}" Width="20"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    
                </ContextMenu>

                <ContextMenu x:Key="memberContextMenuPIM">
                    <MenuItem Header="Rename diagram" Click="OnMemberRenameClick">
                        <MenuItem.Icon>
                            <Image Source="{StaticResource pencil}" Width="20"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Header="Remove diagram" Click="OnMemberRemoveClick">
                        <MenuItem.Icon>
                            <Image Source="{StaticResource delete}" Width="20"/>
                        </MenuItem.Icon>
                    </MenuItem>
                </ContextMenu>
                <ContextMenu x:Key="memberContextMenuPSM">
                    <MenuItem Header="Rename diagram" Click="OnMemberRenameClick">
                        <MenuItem.Icon>
                            <Image Source="{StaticResource pencil}" Width="20"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Header="Remove diagram" Click="OnMemberRemoveClick">
                        <MenuItem.Icon>
                            <Image Source="{StaticResource delete}" Width="20"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <!--MenuItem Header="Change target namespace" Click="OnChangeDiagramTargetNamespaceClick">

                    </MenuItem-->
                </ContextMenu>

                <Style x:Key="projectStyler" TargetType="TextBlock">
                    <Setter Property="Foreground" Value="DarkBlue"/>
                    <Setter Property="FontWeight" Value="Bold" />
                </Style>
                <Style x:Key="namespaceStyler" TargetType="TextBlock">
                    <Setter Property="Foreground" Value="Blue"/>
                    <Setter Property="FontWeight" Value="Bold" />
                </Style>
                <Style x:Key="groupStyler" TargetType="TreeViewItem">
                    <Setter Property="FontWeight" Value="Bold" />
                </Style>
                <Style x:Key="memberStyler" TargetType="TreeViewItem">
                    <Setter Property="FontWeight" Value="Normal" />
                </Style>

                <DataTemplate x:Key="memberTemplatePIM">
                    <TreeViewItem Header="{Binding Path=Caption}" Style="{StaticResource memberStyler}" MouseDoubleClick="OnMemberDoubleClick" MouseUp="OnMemberClick" ContextMenu="{StaticResource memberContextMenuPIM}" Margin="-20,0,0,0"/>
                </DataTemplate>
                <DataTemplate x:Key="memberTemplatePSM">
                    <TreeViewItem Style="{StaticResource memberStyler}" MouseDoubleClick="OnMemberDoubleClick" MouseUp="OnMemberClick" ContextMenu="{StaticResource memberContextMenuPSM}" Margin="-20,0,0,0">
                        <TreeViewItem.Header>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding Path=Caption}"></TextBlock>
                                <TextBlock Text=" target namespace: "></TextBlock>
                                <TextBlock Text="{Binding Path=TargetNamespace,  TargetNullValue='Default Namespace', FallbackValue='Default Namespace'}"></TextBlock>
                            </StackPanel>
                        </TreeViewItem.Header>
                    </TreeViewItem>
                </DataTemplate>

                <Gui:NamespaceVisibilityConverter x:Key="VisibilityConverter"/>
                
                <HierarchicalDataTemplate x:Key="projectTemplate" DataType="{x:Type Model:Project}">
                    <StackPanel>
                        <TreeViewItem IsExpanded="True" ContextMenu="{StaticResource projectContextMenu}" Margin="-20,0,0,0">
                            <TreeViewItem.Header>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding Path=Schema.XMLNamespace}" ToolTip="Project's XML Namespace name" Style="{StaticResource namespaceStyler}" Visibility="{Binding Path=Schema.XMLNamespace, Converter={StaticResource VisibilityConverter}}"/>
                                    <TextBlock Text=":" Style="{StaticResource namespaceStyler}" Visibility="{Binding Path=Schema.XMLNamespace, Converter={StaticResource VisibilityConverter}}"/>
                                    <TextBlock Text="{Binding Path=Caption}" ToolTip="Project's name" Style="{StaticResource projectStyler}" />
                                    <TextBlock Text="{Binding Path=Version/Label}" ToolTip="Project's version" Style="{StaticResource projectStyler}" Margin="3,0,0,0" />
                                </StackPanel>
                            </TreeViewItem.Header>
                            <TreeViewItem Header="PIM Diagrams" IsExpanded="True" Style="{StaticResource groupStyler}" ItemTemplate="{StaticResource memberTemplatePIM}" ItemsSource="{Binding Path=PIMDiagrams}" ContextMenu="{StaticResource PIMDiagramContextMenu}"/>
                            <TreeViewItem Header="PSM Diagrams" IsExpanded="True" Style="{StaticResource groupStyler}" ItemTemplate="{StaticResource memberTemplatePSM}" ItemsSource="{Binding Path=PSMDiagrams}" ContextMenu="{StaticResource PSMDiagramContextMenu}"/>
                        </TreeViewItem>
                    </StackPanel>
                </HierarchicalDataTemplate>
            </TreeView.Resources>
        </TreeView>
    </DockPanel>

</ContentControl>
